#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define sort sort(v.begin(),v.end());
//freopen("sets.in", "r", stdin);
using namespace std;
long long mod=1e9+7;
long long power(long long n, long long m)
{
if (!m)return 1;
if (m==1)return n%mod;
long long lol=power(n,m/2);
return (m&1?((((n%mod)*(lol%mod))%mod)*(lol%mod))%mod:((lol%mod)*(lol%mod))%mod);
}
long long ncr(long long n, long long m)
{
if(m==0)return 1;
return ((((n%mod)*(ncr(n-1,m-1)%mod))%mod)/m)%mod;
}
long long npr(long long n, long long r) {
if (r > n)
return 0;
long long p = 1, i = n - r + 1;
while (i <= n)
p *= i++;
return p;
}
bool prime(long long x)
{
if (x<=1)return 0;
for (int i=2; i<=sqrt(x); i++)
if (!(x%i))
return 0;
return 1;
}
long long fact(long long a)
{
if (!a)return 1; return (a == 1 ? 1 : fact(a - 1) * a);
}
int main()
{
speed
//coming..soon
int t=1;
cin>>t;
while(t--){
long long n, p, l, t;
cin >> n >> p >> l >> t;
long long total =(n+6)/7 ;
long long st = 0, ed = n;
while (st<ed)
{
long long mi = (st + ed + 1) / 2;
long long sum = (n - mi) * l + t * min(total, (n - mi) * 2ll);
if (sum >= p) st = mi;
else ed = mi - 1;
}
cout <<st<< "\n";
}
return 0;
}
Differences of the permutations | Doctor's Secret |
Back to School | I am Easy |
Teddy and Tweety | Partitioning binary strings |
Special sets | Smallest chosen word |
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |